home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / pager / RCS / pager.c,v < prev   
Encoding:
Text File  |  1989-06-16  |  6.7 KB  |  329 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     89.06.16.09.08.06;  author mendel;  state Exp;
  11. branches ;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.12.28.12.05.02;  author mendel;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     87.12.14.09.43.16;  author nelson;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     87.01.12.14.46.36;  author nelson;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 1.4
  35. log
  36. @*** empty log message ***
  37. @
  38. text
  39. @#include <stdio.h>
  40. #include <stdlib.h>
  41. #include <sprite.h>
  42. #include <option.h>
  43. #include <sys/time.h>
  44.  
  45.  
  46. int    pageSize = 4096;
  47. int    numPageFaults = 1000;
  48. int    repeats = 3;
  49. Boolean    pause = FALSE;
  50. Boolean    trace = FALSE;
  51. Boolean dirty = FALSE;
  52. Boolean longcheck = FALSE;
  53. Boolean staticArray = FALSE;
  54. static  char sArray[4*1024*1024];
  55.  
  56. Option optionArray[] = {
  57.     {OPT_INT, "p", (Address)&pageSize,
  58.     "The page size to fault on (default 4096)."},
  59.     {OPT_INT, "n", (Address)&numPageFaults,
  60.     "Number of page faults (default 1000)"},
  61.     {OPT_INT, "r", (Address)&repeats,
  62.     "Number of repeats of faulting sequence (default 3)"},
  63.     {OPT_TRUE, "P", (Address)&pause,
  64.     "Wait for input before starting"},
  65.     {OPT_TRUE, "t", (Address)&trace,
  66.     "Should print out information as page faults happen"},
  67.     {OPT_TRUE, "d", (Address)&dirty,
  68.     "Dirty the page on each pass."},
  69.     {OPT_TRUE, "c", (Address)&longcheck,
  70.     "Do a more complete check of the page."},
  71.     {OPT_TRUE, "s", (Address)&staticArray,
  72.     "Page from the static 4meg array."},
  73. };
  74. int numOptions = sizeof(optionArray) / sizeof(Option);
  75.  
  76. static char    *big;
  77.  
  78. main(argc, argv)
  79.     int  argc;
  80.     char *argv[];
  81. {
  82.     register    char    *bigPtr;
  83.     register    struct timeval    *beforeArr; 
  84.     register    struct timeval    *afterArr;
  85.     register    int    *intPtr;
  86.     register    int    i;
  87.     register    int    j;
  88.     struct    timeval        before, after;
  89.     char        *big;
  90.     char        c;
  91.     Boolean        once = FALSE;
  92.     double        rate;
  93.  
  94.     (void)Opt_Parse(argc, argv, optionArray, numOptions,0);
  95.     if (pause) {
  96.     scanf("%c", &c);
  97.     }
  98.     if (staticArray) {
  99.     big = sArray;
  100.     numPageFaults = 4*1024*1024/pageSize;
  101.     } else { 
  102.     big = (char *)malloc(pageSize * numPageFaults);
  103.     }
  104.     if (big == NULL) {
  105.     fprintf(stderr,"Can't allocated %d bytes of memory.\n",
  106.             pageSize * numPageFaults);
  107.     exit(1);
  108.     }
  109.     beforeArr = (struct timeval *)malloc(sizeof(struct timeval) * repeats);
  110.     afterArr = (struct timeval *)malloc(sizeof(struct timeval) * repeats);
  111.     if (beforeArr == NULL || afterArr == NULL) {
  112.     fprintf(stderr,"Can't allocated memory for timing arrays.\n");
  113.     exit(1);
  114.     }
  115.     gettimeofday(&before, NULL);
  116.     for (j = 0; j < repeats; j++) {
  117.     gettimeofday(&beforeArr[j], NULL);
  118.     for (i = 1, bigPtr = big; i <= numPageFaults; i++, bigPtr += pageSize) {
  119.         intPtr = (int *)bigPtr;
  120.         if (dirty) {
  121.         *intPtr = *intPtr;
  122.         }
  123.         if (!longcheck) {
  124.         if (once && *intPtr != i) {
  125.             printf("Error on page %d address 0x%x ", i, intPtr);
  126.             printf("Found 0x%x should be 0x%x\n",*intPtr,i);
  127.             fflush(stdout);
  128.             abort();
  129.         }
  130.         } else {
  131.         int    *end = intPtr + pageSize/sizeof(int);
  132.         int    *c;
  133.         if (once) {
  134.            for (c = intPtr; c < end; c += 4) {
  135.                if (*c != i) {
  136.                 printf("Error on page %d address 0x%x ", i,intPtr);
  137.                 printf("Found 0x%x should be 0x%x\n",*c,i);
  138.                 fflush(stdout);
  139.             }
  140.             }
  141.         }
  142.         }
  143.         if (trace && (i % 100 == 0)) {
  144.         printf("%d\n", i);
  145.         fflush(stdout);
  146.         }
  147.         if (!once || dirty) {
  148.         if (!longcheck) {
  149.             *intPtr = i;
  150.         } else {
  151.             int    *end = intPtr + pageSize/sizeof(int);
  152.             for (; intPtr < end; intPtr += 4) {
  153.             *intPtr = i;
  154.             }
  155.            }
  156.         }
  157.     }
  158.     gettimeofday(&afterArr[j], NULL);
  159.     once = TRUE;
  160.     if (trace) {
  161.         printf("Pass %d\n\n", j + 1);
  162.         fflush(stdout);
  163.     }
  164.     }
  165.     for (j = 0; j < repeats; j++) {
  166.     rate = (afterArr[j].tv_sec - beforeArr[j].tv_sec) * 1000;
  167.     rate += (afterArr[j].tv_usec - beforeArr[j].tv_usec) / 1000;
  168.     rate = rate / numPageFaults;
  169.     printf("Pass %d: %0.3f ms per page fault\n", j + 1, rate);
  170.     }
  171.  
  172.     gettimeofday(&after,NULL);
  173.     rate = (after.tv_sec - before.tv_sec) * 1000;
  174.     rate += (after.tv_usec - before.tv_usec)*.001;
  175.     rate = rate / (numPageFaults * repeats);
  176.     printf("Totals: time=%0.3f sec, faults=%d rate=%0.3f ms per fault\n", 
  177.         (after.tv_sec - before.tv_sec) + 
  178.         (after.tv_usec - before.tv_usec) / 1000000.0,
  179.         numPageFaults * repeats, rate);
  180.     exit(0);
  181. }
  182. @
  183.  
  184.  
  185. 1.3
  186. log
  187. @Ported to new C library.
  188. @
  189. text
  190. @d7 1
  191. d13 4
  192. d29 6
  193. d60 6
  194. a65 2
  195.  
  196.     big = (char *)malloc(pageSize * numPageFaults);
  197. d82 22
  198. a103 3
  199.         if (once && *intPtr != i) {
  200.         printf("Error on page %d\n", i);
  201.         fflush(stdout);
  202. a104 1
  203.  
  204. d109 9
  205. a117 2
  206.         if (!once) {
  207.         *intPtr = i;
  208. @
  209.  
  210.  
  211. 1.2
  212. log
  213. @Made it more flexible.  Can handle different page sizes and the like for
  214. example.
  215. @
  216. text
  217. @d1 5
  218. a5 5
  219. #include "sprite.h"
  220. #include "time.h"
  221. #include "option.h"
  222. #include "io.h"
  223. #include "time.h"
  224. d14 1
  225. a14 1
  226.     {OPT_INT, 'p', (Address)&pageSize,
  227. d16 1
  228. a16 1
  229.     {OPT_INT, 'n', (Address)&numPageFaults,
  230. d18 1
  231. a18 1
  232.     {OPT_INT, 'r', (Address)&repeats,
  233. d20 1
  234. a20 1
  235.     {OPT_TRUE, 'P', (Address)&pause,
  236. d22 1
  237. a22 1
  238.     {OPT_TRUE, 't', (Address)&trace,
  239. d34 2
  240. a35 2
  241.     register    Time    *beforeArr, before;
  242.     register    Time    *afterArr, after;
  243. d39 1
  244. d45 1
  245. a45 1
  246.     (void)Opt_Parse(&argc, argv, numOptions, optionArray);
  247. d47 1
  248. a47 1
  249.     Io_Scan("%c", &c);
  250. d50 13
  251. a62 4
  252.     big = (char *)Mem_Alloc(pageSize * numPageFaults);
  253.     beforeArr = (Time *)Mem_Alloc(sizeof(Time) * repeats);
  254.     afterArr = (Time *)Mem_Alloc(sizeof(Time) * repeats);
  255.     Sys_GetTimeOfDay(&before, NULL, NULL);
  256. d64 1
  257. a64 1
  258.     Sys_GetTimeOfDay(&beforeArr[j], NULL, NULL);
  259. d68 2
  260. a69 2
  261.         Io_Print("Error on page %d\n", i);
  262.         Io_Flush(io_StdOut);
  263. d73 2
  264. a74 2
  265.         Io_Print("%d\n", i);
  266.         Io_Flush(io_StdOut);
  267. d80 1
  268. a80 1
  269.     Sys_GetTimeOfDay(&afterArr[j], NULL, NULL);
  270. d83 2
  271. a84 2
  272.         Io_Print("Pass %d\n\n", j + 1);
  273.         Io_Flush(io_StdOut);
  274. d88 2
  275. a89 2
  276.     rate = (afterArr[j].seconds - beforeArr[j].seconds) * 1000;
  277.     rate += (afterArr[j].microseconds - beforeArr[j].microseconds) / 1000;
  278. d91 1
  279. a91 1
  280.     Io_Print("Pass %d: %0.3f ms per page fault\n", j + 1, rate);
  281. d94 3
  282. a96 3
  283.     Sys_GetTimeOfDay(&after, NULL, NULL);
  284.     rate = (after.seconds - before.seconds) * 1000;
  285.     rate += (after.microseconds - before.microseconds)*.001;
  286. d98 3
  287. a100 3
  288.     Io_Print("Totals: time=%0.3f sec, faults=%d rate=%0.3f ms per fault\n", 
  289.         (after.seconds - before.seconds) + 
  290.         (after.microseconds - before.microseconds) / 1000000.0,
  291. d102 1
  292. @
  293.  
  294.  
  295. 1.1
  296. log
  297. @Initial revision
  298. @
  299. text
  300. @d3 1
  301. d5 1
  302. d7 5
  303. a11 1
  304. static    int    big[3000][512];
  305. d13 16
  306. d33 10
  307. a42 2
  308.     int        i, j;
  309.     Boolean    once = FALSE;
  310. d44 15
  311. a58 4
  312.     for (j = 1; j <= 3; j++) {
  313.     for (i = 1; i <= 2000; i++) {
  314.         if (once && big[i][0] != i) {
  315.         Io_Print("Error: big[%d][0] = %d\n", i, big[i][0]);
  316. d62 1
  317. a62 1
  318.         if (i % 100 == 0) {
  319. d67 1
  320. a67 1
  321.         big[i][0] = i;
  322. d70 1
  323. d72 4
  324. a75 2
  325.     Io_Print("\nPass %d\n", j);
  326.     Io_Flush(io_StdOut);
  327. d77 15
  328. @
  329.